package com.dys.testwrap;

/**
 * @className: com.dys.testwrap.Student
 * @description: 封装加深练习: 隐藏对象的内部复杂性，只对外公开简单的接口。便于外界调用，从而提高系统的可拓展性、可维护性。
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/07/17 下午10:06
 */
public class Student {
    // 封装
    private String name;
    private int age;
    private char gender;
    private String sex;

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return this.age;
    }

    public void setAge(int age) {
        if (age < 0 || age > 150) {
            throw new IllegalArgumentException("Age must be between 0 and 150");
        } else {
            this.age = age;
        }
    }

    public char getGender() {
        return this.gender;
    }

    public void setGender(char gender) {
        if (gender == '男' || gender == '女') {
            this.gender = gender;
        } else {
            this.gender = '男';
        }
    }

    public String getSex() {
        return this.sex;
    }

    public void setSex(String sex) {
        if ("男".equals(sex) || "女".equals(sex) || "male".equals(sex) || "female ".equals(sex)) {
            this.sex = sex;
        } else {
            this.sex = "保密";
        }
    }

    public Student() {
    }

    public Student(String name, int age, String sex) {
        this.name = name;
        // this.age = age;
        // 控制年龄的范围
        this.setAge(age);
        // this.sex = sex;
        // 构造器控制用户乱输入性别
        this.setSex(sex);
    }
}
